package com.example.project.controller;

import com.example.project.action.ActionUtil;
import com.example.project.base.ResultBean;
import com.example.project.common.MatchesKey;
import com.example.project.entity.FirmVO;
import com.example.project.framework.BaseController;
import com.example.project.service.FirmService;
import com.example.project.util.FunctionUtil;
import com.example.project.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/firm")
@Api(value = "FirmController",tags = "企业管理")
public class FirmController extends BaseController {
    @Autowired
    FirmService firmService;

    @RequestMapping(value = "/editFirm",method = RequestMethod.POST)
    @ApiOperation("修改企业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pkid",value="企业ID",required=true),
            @ApiImplicitParam(name="firmName",value="企业名称"),
            @ApiImplicitParam(name="area",value="所在区域（显示区/县级）‘吴兴区、南浔区、德清县、长兴县、安吉县'"),
            @ApiImplicitParam(name="address",value="企业地址（完整地址）‘浙江省湖州市xx区/县’"),
            @ApiImplicitParam(name="nature",value="企业性质"),
            @ApiImplicitParam(name="scale",value="企业规模"),
            @ApiImplicitParam(name="industry",value="所属行业"),
            @ApiImplicitParam(name="logoUrl",value="公司LOGO‘/xxx/xxx/xx.jpg’"),
            @ApiImplicitParam(name="qualification",value="资质证明‘/xxx/xxx/xx.jpg,/xxx/xxx/xx.jpg,/xxx/xxx/xx.jpg’"),
            @ApiImplicitParam(name="theContact",value="企业联系人姓名"),
            @ApiImplicitParam(name="contact",value="联系方式"),
            @ApiImplicitParam(name="introduce",value="公司简介"),
            @ApiImplicitParam(name="endTime",value="有效时间：‘YYYY-MM-DD HH:mm:ss’"),
            @ApiImplicitParam(name="school",value="传入‘1’会生成高校申请，需要管理员进行审核"),
    })
    public ResultBean editFirm(){
        firmService.editFirm(ActionUtil.getParameterMap());
        return ok("成功");
    }

    @RequestMapping(value = "/addFirm",method = RequestMethod.POST)
    @ApiOperation("添加企业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="firmName",value="企业名称",required=true),
            @ApiImplicitParam(name="area",value="所在区域（显示区/县级）‘吴兴区、南浔区、德清县、长兴县、安吉县'",required=true),
            @ApiImplicitParam(name="address",value="企业地址（完整地址）‘浙江省湖州市xx区/县’",required=true),
            @ApiImplicitParam(name="nature",value="企业性质",required=true),
            @ApiImplicitParam(name="scale",value="企业规模",required=true),
            @ApiImplicitParam(name="industry",value="所属行业",required=true),
            @ApiImplicitParam(name="logoUrl",value="公司LOGO‘/xxx/xxx/xx.jpg’",required=true),
            @ApiImplicitParam(name="qualification",value="资质证明‘/xxx/xxx/xx.jpg,/xxx/xxx/xx.jpg,/xxx/xxx/xx.jpg’",required=true),
            @ApiImplicitParam(name="theContact",value="企业联系人姓名",required=true),
            @ApiImplicitParam(name="contact",value="联系方式",required=true),
            @ApiImplicitParam(name="introduce",value="公司简介",required=true),
            @ApiImplicitParam(name="endTime",value="有效时间：‘YYYY-MM-DD HH:mm:ss’",required=true),
    })
    public ResultBean addFirm(FirmVO vo){
        FunctionUtil.check(StringUtil.isEmpty(vo.getFirmName()),"请输入企业名称！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getArea()),"请输入所在区域！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getNature()),"请输入企业性质！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getScale()),"请输入企业规模！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getIndustry()),"请输入所属行业！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getLogoUrl()),"请上传公司LOGO！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getQualification()),"请上传资质证明！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getTheContact()),"请输入企业联系人姓名！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getContact()),"请输入联系方式！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getIntroduce()),"请输入公司简介！");
        FunctionUtil.check(StringUtil.isEmpty(vo.getEndTime()),"请选择有效时间！");
        FunctionUtil.check(!vo.getContact().matches(MatchesKey.PHONE_MATCHES),"企业联系方式不正确！如：18200001111！");
        return ok("成功",firmService.addFirm(vo));
    }

    @RequestMapping(value = "/getFirmList",method = RequestMethod.POST)
    @ApiOperation("获取企业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pkid",value="企业ID"),
            @ApiImplicitParam(name="contact",value="联系方式"),
            @ApiImplicitParam(name="audit",value="审核状态 (-1未审核/未通过0/1已通过)"),
            @ApiImplicitParam(name="school",value="传入‘1’会生成高校申请，需要管理员进行审核"),
            @ApiImplicitParam(name="search",value="模糊查询"),
    })
    public ResultBean getFirmList(Map paramMap){
        return ok("成功",firmService.getFirmList(paramMap));
    }

    @RequestMapping(value = "/delFirm",method = RequestMethod.POST)
    @ApiOperation("删除企业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pkid",value="企业ID"),
    })
    public ResultBean delFirm(Integer pkid){
        firmService.deleteById(pkid);
        return ok("成功");
    }

    @RequestMapping(value = "/firmSort",method = RequestMethod.POST)
    @ApiOperation("企业排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pkid",value="企业ID"),
            @ApiImplicitParam(name="sort",value="0向下/1向上"),
    })
    public ResultBean firmSort(Integer pkid,Integer sort){
        firmService.firmSort(pkid,sort);
        return ok("成功");
    }
}
